<?php
/**
 * @package pmapi
 * @copyright Copyright (c)2014 Enrico Fagnoni
 * @license GNU General Public License version 3, or later
 *
 * @since 1.0.0
 */
 
defined('_JEXEC') or die;
 
// import Joomla modelitem library
jimport('joomla.application.component.model');
 
class PmapiModelOntology extends JModel
{
    
    public function getShopperGroups()
    {

        $db = JFactory::getDBO();
        $query =  $db
            ->getQuery(true)
            ->select('virtuemart_shoppergroup_id, shopper_group_name, shopper_group_desc')
            ->from( '#__virtuemart_shoppergroups' )
            ->where( 'published = 1');
    
        $db->setQuery($query);
        //print_r($db->loadObjectList());die($query);

        return $db->loadObjectList();
    }

    public function getProductCategories()
    {
        $db = JFactory::getDBO();
        $query =  $db
            ->getQuery(true)
            ->select( 'virtuemart_category_id')
            ->from('#__virtuemart_categories')
        ;
        // the full list of categories is available only to admins
        //if(!class_exists('Permissions')) require(JPATH_VM_ADMINISTRATOR.DS.'helpers'.DS.'permissions.php');
        //if( !Permissions::getInstance()->check('admin') ){
        //    $query->where ('published = 1 OR shared = 1');
        //}          
        $db->setQuery($query);
        $categoryIDs = $db->loadColumn();
        
        // load categories
        $categories = array();
        if(!class_exists('VirtueMartModelCategory')) require(JPATH_VM_ADMINISTRATOR.DS.'models'.DS.'category.php');
        $categoryModel = new VirtueMartModelCategory;
        foreach ($categoryIDs as $cid){
            $category = $categoryModel->getCategory($cid);
            if (!empty($category)){
                $categoryModel->addImages($category);
                $categories[] = (object) get_object_vars($category);
            }
        }
 
        return $categories;          
    }    
}